<?php

namespace Admin\Controller;
use Home\Model\AdModel;
/**
 * 后台内容控制器
 * @author huajie <banhuajie@163.com>
 */
class AdController extends CommonController {
	
	//广告列表
	public function index() {
        $map = $this->_search();
        $map['type'] = $type = I('type', AdModel::TYPE_AD);
        if (!empty($this->model)) {
            $list = $this->lists($this->model, $map);
            $this->assign($this->tableName.'List', $list);
        }

		$this->display();
//        if($type==AdModel::TYPE_AD){
//            $this->display(__FUNCTION__.AdModel::TYPE_AD_NAME);
//        }else{
//            $this->display(__FUNCTION__.AdModel::TYPE_FL_NAME);
//        }
	}
	
	//广告添加
	public function add() {
		if(IS_POST) {
			$data = I();
			
			$result = M("Ad")->add($data);
            if(is_numeric($result)){
                $this->success('添加成功！');
            }
		    $this->error('添加失败！');
		}else{
			$type = I('get.type');
			$this->assign('type',$type);
		}
		$this->display();
	}
	
	public function edit() {
		$ad = M("Ad");
		if(IS_POST) {
			$condition['id']  = I('request.id');
			$data = I();
			
			$result = $ad->where($condition)->save($data);
			FPC(M()->getLastSql());
			if(is_numeric($result)){
				$this->success('更新成功！');
			}
			$this->error('更新失败！');
		}else{
            $id = I('get.id');
            $info = $ad->find($id);
            $this->assign('vo', $info);
            $this->display();
        }
	}
	
}